#!/bin/bash

echo "build ..."
rm -rf output
mkdir output
if [ "package-eureka" = $1 ] ; then
    mvn clean package -pl eureka
    cp eureka/target/eureka.jar output/
    cp eureka/Dockerfile output/
elif [ "package-provider" = $1 ] ; then
    mvn clean package -pl provider
    cp provider/target/provider.jar output/
    cp provider/Dockerfile output/
elif [ "package-consumer" = $1 ] ; then
    mvn clean package -pl consumer
    cp consumer/target/consumer.jar output/
    cp consumer/Dockerfile output/
elif [ "package-gateway" = $1 ] ; then
    mvn clean package -pl gateway
    cp gateway/target/gateway.jar output/
    cp gateway/Dockerfile output/
elif [ "package-hystrix-dashboard" = $1 ] ; then
    mvn clean package -pl hystrix-dashboard
    cp hystrix-dashboard/target/hystrix-dashboard.jar output/
    cp hystrix-dashboard/Dockerfile output/
elif [ "package-config-server" = $1 ] ; then
    mvn clean package -pl config-server
    cp config-server/target/config-server.jar output/
    cp config-server/Dockerfile output/
elif [ "package-all" = $1 ] ; then
    mvn clean package
    mkdir output/eureka
    cp eureka/target/eureka.jar output/eureka
    cp eureka/Dockerfile output/eureka
    mkdir output/provider
    cp provider/target/provider.jar output/provider
    cp provider/Dockerfile output/provider
    mkdir output/consumer
    cp consumer/target/consumer.jar output/consumer
    cp consumer/Dockerfile output/consumer
    mkdir output/gateway
    cp gateway/target/gateway.jar output/gateway
    cp gateway/Dockerfile output/gateway
    mkdir output/hystrix-dashboard
    cp hystrix-dashboard/target/hystrix-dashboard.jar output/hystrix-dashboard
    cp hystrix-dashboard/Dockerfile output/hystrix-dashboard
    mkdir output/config-server
    cp config-server/target/config-server.jar output/config-server
    cp config-server/Dockerfile output/config-server
elif [ "clean-all" = $1 ] ; then
    mvn clean
    rm -rf output
fi
echo "build done."